package com.qf.servlet;

import com.qf.pojo.Category;
import com.qf.service.CategoryService;
import com.qf.service.impl.CategoryServiceImpl;
import com.qf.utils.JsonUtils;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/category")
public class CategoryServlet extends baseServlet {
    //查询分类表
    public void findCategory(HttpServletRequest request,HttpServletResponse response) throws IOException {
        //调用业务层
        CategoryService categoryService = new CategoryServiceImpl();
        List<Category> list = categoryService.findCategory();
        System.out.println(list);
        //需要返回一个json形式,使用json的依赖提供的工具JSONUtils
        String str = JsonUtils.list2json(list);
        //将json响应给浏览器
        response.getWriter().write(str);

    }

}
